import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'
import * as types from './mutation-types'
import {appRoute} from '../router/index'

Vue.use(Vuex)

// 应用初始状态
const state = {
  count: 10,
  appName: 'Spdex Translation Demo',
  menu: []
}

// 定义所需的 mutations
const mutations = {
  INCREMENT(state) {
    state.count++
  },
  DECREMENT(state) {
    state.count--
  },
  [types.INIT_APP](state, data) {
    let appMenu = [{heading: appRoute.text}]
    appRoute.children.forEach(m => {
      if (!m.meta || !m.meta.hidden) {
        let me = {uri: m.name, icon: m.icon, text: m.text, 'icon-alt': m.iconAlt, model: false}
        if (m.children && m.children.length > 0) {
          me.children = []
          m.children.forEach(child => {
            if (!child.meta || !child.meta.hidden) {
              me.children.push({uri: child.name, icon: child.icon, text: child.text})
            }
          })
        }
        appMenu.push(me)
      }
    })
    state.menu = appMenu
  }
}
// {
// path: '/hw',
// name: 'HelloWorld',
// component: HelloWorld,
// meta: {
//   requireAuth: true
// }
// {icon: 'contacts', text: 'Contacts'},
// {icon: 'history', text: 'Frequently contacted'},
// {icon: 'content_copy', text: 'Duplicates'},
// {
// icon: 'keyboard_arrow_up',
// 'icon-alt': 'keyboard_arrow_down',
// text: 'Labels',
// model: true,
// children: [{icon: 'add', text: 'Create label'}]
// },
// {
// icon: 'keyboard_arrow_up',
// 'icon-alt': 'keyboard_arrow_down',
// text: 'More',
// model: false,
// children: [{text: 'Import'}, {text: 'Export'}, {text: 'Print'}, {text: 'Undo changes'}, {text: 'Other contacts'}]
// },
// {icon: 'settings', text: 'Settings'},
// {icon: 'chat_bubble', text: 'Send feedback'},
// {icon: 'help', text: 'Help'},
// {icon: 'phonelink', text: 'App downloads'},
// {icon: 'keyboard', text: 'Go to the old version'}
// 创建 store 实例
export default new Vuex.Store({
  actions,
  getters,
  state,
  mutations
})
